package com.young.shop.admin.controller;


import com.young.shop.admin.service.DataService;
import com.young.shop.pojo.vo.BaseRespVO;
import com.young.shop.pojo.vo.CenterDataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 查询数据
 */

@Api(tags = "数据中心业务")
@RestController
@RequestMapping("/Data")
public class DataController extends BaseController {
    @Autowired
    private DataService dataService;

    @ApiOperation("查询概况数据")
    @GetMapping("/initData")
    public BaseRespVO info(){
        System.out.println("进入查询数据中心");
        try {
            CenterDataVO allInfo = dataService.getAllInfo();
            return convertSuccessResult(allInfo);
        } catch (RuntimeException e) {
            String errorMsg = e.getMessage();
            return convertErrorResult(errorMsg);
        }

    }

    @ApiOperation("查询个人中心数据")
    @GetMapping("/analyse")
    public BaseRespVO analyseData(){
        System.out.println("进入数据分析");
        try {
            List<CenterDataVO> countByHours = dataService.getCountByHours();
            return convertSuccessResult(countByHours);
        } catch (RuntimeException e) {
            String errorMsg = e.getMessage();
            return convertErrorResult(errorMsg);
        }
    }

    @ApiOperation("查询个人中心数据1")
    @GetMapping("/analyse1")
    public BaseRespVO analyseData1(){
        System.out.println("进入数据分析1");
        try {
            List<CenterDataVO> countByHours = dataService.getViewsByDate();
            return convertSuccessResult(countByHours);
        } catch (RuntimeException e) {
            String errorMsg = e.getMessage();
            return convertErrorResult(errorMsg);
        }
    }


}
